package com.lizanyi.teaFriend.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.lizanyi.teaFriend.pojo.TeaAdmin;
import com.lizanyi.teaFriend.tools.Constans;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;
import org.springframework.web.servlet.HandlerAdapter;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;



@Component
public class SysInterceptor implements HandlerInterceptor {
	private Logger logger = Logger.getLogger(SysInterceptor.class);

	public boolean preHandle(HttpServletRequest request,
			 HttpServletResponse response, Object handler) throws Exception {
		logger.debug("SysInterceptor preHandle ==========================");
		HttpSession session = request.getSession();

		TeaAdmin teadmin = (TeaAdmin) session.getAttribute(Constans.ADMIN_SESSION);

		if (null == teadmin) {
			System.out.println("拦截请求");
			request.setAttribute("error","请先登录，再进管理员页面");
			request.getRequestDispatcher("/").forward(request,response);
			return false;
		}
		return true;
	}
}
